<script>
//公共的列表页
$(document).ready(function(){
	{params}
	var c = {
		num:'',
		cnum:'',
		pnum:'',
		atype:'',
		gtype:'',
		funitid:'',
		searchtxt:'',
		init:function(){
			this.num 	= params.num;
			if(params.cnum)this.cnum 	= params.cnum;
			if(params.pnum)this.pnum 	= params.pnum;
			if(params.atype)this.atype 	= params.atype;
			if(params.funitid)this.funitid = params.funitid;
			if(params.gtype)this.gtype 	= params.gtype;
			if(params.sqlwhere)this.sqlwhere 	= params.sqlwhere;
			$('#toolcetner_{rand}').html(document.title);
			this.resize();
			importjs('list', function(){
				c.createlist();
			});
		},
		resize:function(){
			//var meih = viewheight-22;
			//xcy.setheight('view_{rand}', meih);
		},
		createlist:function(){
			var url = 'api/flow/listinit?num='+this.num+'';
			if(this.pnum)url+='&pnum='+this.pnum+'';
			js.ajax.get({
				url:url,
				cnum:this.cnum,
				funitid:this.funitid,
				onsuccess:function(ret){
					c.loadshow(ret.data);
				},
				onerror:function(ret){
					$('#view_{rand}').html(ret.msg);
				}
			});
		},
		loadshow:function(da){
			if(da.isadd==1)this.addshow();
			this.initdata= da;
			this.showatype(da.atypearr);
			this.listobj = new js.list.create({
				view:'view_{rand}',
				num:this.num,
				cnum:this.cnum,
				pnum:this.pnum,
				funitid:this.funitid,
				atype:this.atype,
				gtype:this.gtype,
				sqlwhere:this.sqlwhere,
				showtype:'1',
				modejs:da.modejs,
				moders:da.moders,
				isadd:da.isadd,
				optobj:this,
				params:params,
				rand:'{rand}'
			});
		},
		showatype:function(da){
			var i,len=da.length,d,s='',act;
			this.atypediv = 'atypediv_{rand}';
			for(i=0;i<len;i++){
				act = '';
				d 	= da[i];
				if(i==0 || this.atype==d.num){
					act=' active';
					this.atype = d.num;
				}
				s+='<div clickevt="changeatype,'+d.num+'" class="rock-tabbar-item '+act+'">'+d.name+'</div>';
			}
			if(s){
				$('#'+this.atypediv+'').html(s).show();
				js.initbtn(this,this.atypediv);
			}
		},
		changeatype:function(o1,lx){
			$('#'+this.atypediv+'').find('div').removeClass('active');
			$(o1).addClass('active');
			this.atype = lx;
			if(this.listobj)this.listobj.setparams({atype:lx});
		},
		addshow:function(){
			$('#toolleft_{rand}').show();
		},
		addhide:function(){
			$('#toolleft_{rand}').hide();
		},
		adds:function(o1){
			this.listobj.addmenu(o1)
		},
		add:function(){
			this.listobj.addopen(false);
		},
		searchtan:function(){
			js.modal.prompt({
				title:'搜索',
				msg:'输入关键词搜索',
				type:'text',value:this.searchtxt
			}, function(jg,txt){
				if(jg=='yes')c.searchtans(txt);
			});
		},
		searchtans:function(s){
			this.searchtxt = s;
			if(this.listobj)this.listobj.search(s);
		},
		search:function(){
			if(this.listobj)this.listobj.search(get('key_{rand}').value);
		},
		searchhei:function(o){
			if(!this.initdata)return;
			var da = [];
			if(this.initdata.isdaochu==1)da.push({name:'导出',lx:1});
			if(this.initdata.isdaoru==1)da.push({name:'导入',lx:2});
			importjs('menu','create', {
				obj:$(o),data:da,
				onclick:function(d1){
					
				}
			});
		},
		daochu:function(){
			
		},
		showleft:function(st){
			$('#menu_{rand}').show();
			$('#viewlefttitle_{rand}').html(st);
		},
		showmenu:function(){
			$('#viewleft_{rand}').show();
		},
		hidemenu:function(){
			$('#viewleft_{rand}').hide();
		},
		leftcontid:function(){
			return 'viewcont_{rand}';
		},
		addright:function(s,o){
			if(!this.addrightbo){
				$('#atypediv_{rand}').append('<div clickevt="menumore" class="rock-tabbar-item">操作 <i class="icon-caret-up"></i></div>');
				this.addrightbo = true;
				js.initbtn(this, 'atypediv_{rand}');
			}
		},
		addbtn:function(btn,evt, o, ys){
			if(!this.addbtndata)this.addbtndata=[];
			this.addbtndata.push({name:btn,evt:evt,obj:o});
			this.addright('', o);
		},
		menumore:function(o){
			var da = [{name:'新增'}];
			importjs('menu','create', {
				obj:$(o),data:this.addbtndata,width:120,
				bottomheight:50,
				onclick:function(d1,o){
					d1.obj[d1.evt](o);
				}
			});
		}
	}
	js.initbtn(c);
});
</script>

<div style="position:absolute;z-index:2;top:0px;left:0px;background:white;width:230px;border-right:.5px #dddddd solid;display:none" id="viewleft_{rand}">
	<div style="line-height:40px;height:40px;overflow:hidden" class="rock-border-b">
		<div style="float:left;padding:0px 10px" id="viewlefttitle_{rand}">选项</div>
		<div clickevt="hidemenu" style="padding:0px 10px;line-height:40px;float:right" class="btnwe"><i class="icon-caret-left"></i></div>
	</div>
	<div resizes="40" style="height:400px;overflow:auto" id="viewcont_{rand}"></div>
</div>

<div style="height:40px;overflow:hidden;background:white;" class="rock-border-b">
	<table width="100%" height="40"><tr>
	<td id="menu_{rand}" style="display:none"><div clickevt="showmenu" style="padding:0px 10px;line-height:40px;"  class="btnwe"><i class="icon-th-list"></i></div></td>
	<td id="toolcetner_{rand}" width="100%" align="center"></td>
	<td><div style="padding:0px 10px;line-height:40px" class="btnwe" clickevt="searchtan"><i class="icon-search"></i></div></td>
	<td id="toolleft_{rand}" style="display:none"><div clickevt="add" style="padding:0px 10px;line-height:40px" class="btnwe"><i class="icon-plus"></i></div></td>
	</tr></table>
</div>

<div id="view_{rand}" resizes="102" style="height:300px;overflow:auto;">
	<div align="center" style="padding-top:50px" ><i style="height:40px;width:40px" class="rock-loading"></i></div>
</div>

<div id="atypediv_{rand}" style="position:fixed;" class="rock-border-t rock-tabbar"></div>
